package utils;

import java.util.Date;

import javax.persistence.Query;

import play.db.jpa.JPA;

public class Nodepartdate {
	
	
	public static void setdepartdate(String netticketid,Date olddepartdate,Date newdepartdate) throws Exception{
		
		
		String querynodepartdate="select count(1) from nodepartdate n where n.netticketid=:netticketid and	n.olddepartdate =:olddepartdate and	n.newdepartdate =:newdepartdate  ";
		Query query=JPA.em().createNativeQuery(querynodepartdate);
		query.setParameter("netticketid", netticketid);
		query.setParameter("olddepartdate", olddepartdate);
		query.setParameter("newdepartdate", newdepartdate);
		Integer count = 1;
		try {
			count = Integer.parseInt(query.getSingleResult().toString());
		} catch (Exception e) {
			count = 1;
		}
		if (count == 0){
			String insernodepartdate="INSERT INTO nodepartdate ( netticketid, olddepartdate, newdepartdate, createtime,isupdate) VALUES ( :netticketid,:olddepartdate,:newdepartdate, now(),0) ";
			Query insert = JPA.em().createNativeQuery(insernodepartdate);
			insert.setParameter("netticketid", netticketid);
			insert.setParameter("olddepartdate",olddepartdate);
			insert.setParameter("newdepartdate",newdepartdate);
			insert.executeUpdate();
		}
		
	}

}
